<?php

namespace Block\Controllers;

use Illuminate\Http\Request;
use Block\Model\Markets as MarketsModel;
use Block\Model\Language;

/**
 *  交易所
 */
class MarketsController extends Controller
{
    
    protected $lang;
    /**
     * 构造函数
     */
    public function __construct()
    {
        //获取已开启的语言
        // $this->lang = Language::where('status', '0')->get();
    }

    /**
     * 交易所列表
     *
     * @return void
     */
    public function index(){

        $Model=new MarketsModel();
        $data=$Model->orderBy('id','ASC')->paginate(15);
        $response=$data->toArray();
        
        return $this->response($response);
       
    }

    

    /**
     * 交易所详情
     *
     * @param string $name
     * @return void
     */
    public function details(string $name=null){
        $Model=new MarketsModel();
        $data=$Model->where('name',$name)->get([
                                                "display_name",
                                                "home_url",
                                                "volume",
                                                "display_volume",
                                                "status",
                                                "ping",
                                                "has_kline",
                                                "timestamps",
                                                "inflow_30m",
                                                "outflow_30m",
                                                "inflow_1h",
                                                "outflow_1h",
                                                "inflow_1d",
                                                "outflow_1d",
                                                "inflow_1w",
                                                "outflow_1w"
                                            ]);
        $response=[];
        if($data){
            $response=$data->toArray(); 
            return $this->response($response[0]);
            
        }else{
            return $this->response([],404,'Not found');
        }
        
    }

    
}
